﻿//
// Created by work on 24-5-30.
//

#ifndef IOT_PLAT_CUSERINFO_H
#define IOT_PLAT_CUSERINFO_H

#include <shlib/CValue.h>
#include <map>

class CUserInfo{
public:
    enum EUserType {
        ERoot,
        EUser,
        EGuest
    };

    enum ERtUserCol{
        ECommunication_key,
        EState,
        EPulse,
        ELogin_time,
    };

    enum EUserCol {
        EUserId = 0X00,
        EPwd,
        ENickname,
        EUtype,
        EAdmin_usr,
        EConfigs,
        EMenu_permission,
        EProperty_permission,
        EGroupings,
        ECreate_time,
        EUpdate_time,
        ELast_online_time,
        ELast_login_time,
        EMail_address,
        EPhone_number
    };


    QString userid;
    QString pwd;
    QString nickname;
    enum EUserType utype;
    QString admin;
    QJsonObject configs;
    QJsonObject menu_permission;
    QJsonObject property_permission;
    QString grouping;
    QDateTime create_time;
    QDateTime update_time;
    QDateTime last_online_time;
    QDateTime last_login_time;
    QString email_address;
    QString phone_number;

    static std::map<CUserInfo::EUserCol, QString> userColToStringMap;
public:
    explicit CUserInfo();
    QJsonObject toJson();
    void fromJson(const QJsonObject& json);
};

static const std::map<CUserInfo::ERtUserCol, QString> userRtColToStringMap = {
    {CUserInfo::ECommunication_key, "communication_key"},
    {CUserInfo::EState, "state"},
    {CUserInfo::EPulse, "pulse"},
    {CUserInfo::ELogin_time, "login_time"}
};

static const char* t_user_name = "t_iot_user";

#define USER_ENUM                     CUserInfo::EUserCol
#define userFieldName(type)           CUserInfo::userColToStringMap.find(type)->second



#endif //IOT_PLAT_CUSERINFO_H
